import 'dart:async';
import 'dart:ui';
import 'package:cached_network_image/cached_network_image.dart';
//import 'package:kzcity_picker/kzcity_picker.dart';
import 'package:magic_car/UI/webview.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:toast/toast.dart';
import 'package:flutter/material.dart';
import 'package:magic_car/util/HttpHelper.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
 import 'package:city_pickers/city_pickers.dart';

class ShenhePage extends StatefulWidget {
  // ShenhePage({Key key, this.title}) : super(key: key);

  final String sid;
  ShenhePage(this.sid);

  @override
  _MyHomePageState createState() => new _MyHomePageState(this.sid);
}

class _MyHomePageState extends State<ShenhePage> {
  final String sid;
  _MyHomePageState(this.sid);
  TextEditingController _nametroller = new TextEditingController();
  TextEditingController _agetroller = new TextEditingController();
  TextEditingController _mobiletroller = new TextEditingController();
  TextEditingController _validtroller = new TextEditingController();
  TextEditingController _idcardtroller = new TextEditingController();
  TextEditingController _expricetroller = new TextEditingController();
  TextEditingController _passtroller = new TextEditingController();
  TextEditingController _confirmpasstroller = new TextEditingController();
  TextEditingController _failresonController = new TextEditingController();
  TextEditingController _undertestnameController = new TextEditingController();
  TextEditingController _undertestscroeController = new TextEditingController();
  List formList;
  bool agreen = false;
  File _image;
  String card_z = '';
  String card_f = '';
  bool select_img = false;
  Timer _timer;
  int _seconds = 60;
  String _verifyStr = '获取验证码';
  var score = '0';
  var underlinescore = '0';
  var underlinename = '暂无';
  var Inspector_data ;

  String areaStr = '省份/县市/区域';

  String infostaus = '通过';
  String status_string = "";

  String provinceId = '';
  String provinceName = '';
  String cityName = '';
  String cityId = '';
  String areaName = '';
  String areaId = '';
  String site_name = '选择站点';
  List sites=[];
  String siteId = "";

  initState() {
    super.initState();
    formList = [
      {
        "title": '客户姓名',
        'sub_title': '云A00001',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '车牌号',
        'sub_title': '云A00001',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '车牌号',
        'sub_title': '云A00001',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '车牌号',
        'sub_title': '云A00001云A00001云A00',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
    ];
    loadData();
    loadsiteData();
  }
  //加载站点数据
  loadsiteData() async {
    Map<String, String> map = new Map();
    SharedPreferences pref = await SharedPreferences.getInstance();
    map["pid"] = pref.getString('uid');

    print(map);

    HttpHelper.post(HttpHelper.API_GetSites, (data) async {
      if (data != null) {
        print(data);
        setState(() {
          sites = data['info'];
        });
      }
    }, params: map);
  }
//加载数据
  loadData() async {
    Map<String, String> map = new Map();

    map["sid"] = this.sid;

    print(map);

    HttpHelper.post(HttpHelper.API_Inspectorinfo, (data) async {
      if (data != null) {
        print(data);

        if (data["code"] == "0") {
          Toast.show('无相关信息', context);
        } else {
          var info = data['info'];
          _nametroller.text = info['name'];
          _agetroller.text = info['lengthofservice'];
          _mobiletroller.text = info['mobile'];
          _expricetroller.text = info['workhistory'];
          _idcardtroller.text = info['idcard'];

          setState(() {
            score = info['score']==null?score:info['score'];
            underlinescore = info['underline_score']==null?underlinescore:info['underline_score'];
            underlinename = info['underline_test_name']==null?underlinename:info['underline_test_name'];
            Inspector_data = info;
            areaStr = info['provinceName'] +
                '/' +
                info['cityName'] +
                '/' +
                info['areaName'];
            provinceName = info['provinceName'];
            cityName = info['cityName'];
            areaName = info['areaName'];
            provinceId = info['provinceId'];
            cityId = info['cityId'];
            areaId = info['areaId'];
            card_z = info['idcardfront'];
            card_f = info['idcardback'];
            status_string = info['status_string'];
            site_name = info['site_name'];
            siteId = info['site_id'].toString();
            // siteInfo = data["info"];
          });
        }
      }
    }, params: map);
  }
showSiteView() {
    showModalBottomSheet(
        context: context,
        builder: (BuildContext context) {
          return showSite();
        });
  }
   Widget siteView() {
    List<Widget> tiles = [];
    Widget content;
    for (var item in sites) {
      tiles.add(GestureDetector(
          onTap: () {
            // time_str = item;
            Navigator.of(context).pop();
            setState(() {
              site_name = item['name'];
              siteId = item['id'].toString();
            });
           
          },
          child: Container(
              height: 40, child: Center(child: new Text(item['name'])))));
    }

    content = new Column(
        children: tiles //重点在这里，因为用编辑器写Column生成的children后面会跟一个<Widget>[]，
        //此时如果我们直接把生成的tiles放在<Widget>[]中是会报一个类型不匹配的错误，把<Widget>[]删了就可以了
        );
    return content;
  }

  Widget showSite() {
    return new Container(
      height: 300.0,
      child: new Column(
        children: <Widget>[
          new Padding(
            padding: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 0.0),
            child: new Container(
                height: 240.0,
                child: new ListView(children: <Widget>[siteView()])),
          ),
          new Container(
            height: 0.5,
            color: Colors.blueGrey,
          ),
          new Center(
            child: new Padding(
              padding: EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 8.0),
              child: GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: () {
                    Navigator.of(context).pop();
                   
                  },
                  child: new Text(
                    '全部',
                    style:
                        new TextStyle(fontSize: 18.0, color: Colors.blueGrey),
                  )),
            ),
          ),
        ],
      ),
    );
  }
  Widget buildcontent() {
    List<Widget> tiles = [];
    Widget content;
    var name = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '姓名',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '*',
                              style: TextStyle(fontSize: 14, color: Colors.red))
                        ]),
                  ),
                ),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                      controller: _nametroller,
                      decoration: InputDecoration(
                        hintText: '请输入姓名',
                        border: OutlineInputBorder(
                          borderSide: BorderSide.none,
                        ),
                      ),
                      onChanged: (val) {
                        print(val);
                      },
                    )),
                flex: 2,
              )
            ],
          ),
        ));
    var age = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new Text(
                      '工龄',
                      style: TextStyle(
                          fontSize: 15,
                          color: Color.fromRGBO(102, 102, 102, 1)),
                    )),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        controller: _agetroller,
                        keyboardType: TextInputType.number,
                        decoration: InputDecoration(
                          hintText: '请输入工龄',
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 2,
              )
            ],
          ),
        ));

    var city = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: new GestureDetector(
            onTap: () async {
              FocusScope.of(context).requestFocus(FocusNode());
              return;
              // final result =
              //                     await KzcityPicker.showPicker(context);

              //                 if (result != null) {
              //                   setState(() {
              //                      provinceName = result.province;
              //                     provinceId = result.provinceCode.toString();
              //                     cityName = result.city;
              //                     cityId = result.cityCode.toString();
              //                     areaName = result.area;
              //                     areaId = result.areaCode.toString();
              //                     setState(() {
              //                       areaStr =
              //                           provinceName + cityName + areaName;
              //                     });
              //                     // provincename = result.province;
              //                     // cityname = result.city;
              //                     // areaname = result.area;

              //                     // areaStr = "${result.city}/${result.area}";
              //                     // data["value"] = areaStr;
              //                   });
              //                 }
              Result result = await CityPickers.showCityPicker(
                  context: context,
                  cancelWidget:
                      Text('取消', style: TextStyle(color: Colors.black54)),
                  confirmWidget:
                      Text("确定", style: TextStyle(color: Colors.blue)));
              print(result);
              if (result != null) {
                setState(() {
                  provinceName = result.provinceName;
                  provinceId = result.provinceId.toString();
                  cityName = result.cityName;
                  cityId = result.cityId.toString();
                  areaName = result.areaName;
                  areaId = result.areaId.toString();

                  areaStr =
                      "${result.provinceName}/${result.cityName}/${result.areaName}";
                  // this.area =
                  //     "${result.provinceName}/${result.cityName}/${result.areaName}";
                });
              }
            },
            child: Container(
              color: Colors.white,
              height: 50,
              child: new Row(
                children: <Widget>[
                  Expanded(
                    child: new Padding(
                      padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                      child: RichText(
                        text: TextSpan(
                            text: '地区选择',
                            style: TextStyle(
                                fontSize: 15,
                                color: Color.fromRGBO(102, 102, 102, 1)),
                            children: [
                              TextSpan(
                                  text: '*',
                                  style: TextStyle(
                                      fontSize: 14, color: Colors.red))
                            ]),
                      ),
                    ),
                    flex: 1,
                  ),
                  Expanded(
                    child: new Padding(
                        padding: new EdgeInsets.fromLTRB(25, 0, 10, 0),
                        child: new GestureDetector(child: new Text(areaStr))),
                    // new Padding(
                    //     padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    //     child: new GestureDetector(child: new Text('城市'))),
                    // new Padding(
                    //     padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    //     child: new GestureDetector(child: new Text('区/县'))),
                    flex: 2,
                  )
                ],
              ),
            )));
            var site = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: new GestureDetector(
            onTap: () async {
              FocusScope.of(context).requestFocus(FocusNode());
              showSiteView();
            },
            child: Container(
              color: Colors.white,
              height: 50,
              child: new Row(
                children: <Widget>[
                  Expanded(
                    child: new Padding(
                      padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                      child: RichText(
                        text: TextSpan(
                            text: '站点',
                            style: TextStyle(
                                fontSize: 15,
                                color: Color.fromRGBO(102, 102, 102, 1)),
                            children: [
                              TextSpan(
                                  text: '*',
                                  style: TextStyle(
                                      fontSize: 14, color: Colors.red))
                            ]),
                      ),
                    ),
                    flex: 1,
                  ),
                  Expanded(
                    child: new Padding(
                        padding: new EdgeInsets.fromLTRB(25, 0, 10, 0),
                        child: new GestureDetector(child: new Text(site_name))),
                    // new Padding(
                    //     padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    //     child: new GestureDetector(child: new Text('城市'))),
                    // new Padding(
                    //     padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    //     child: new GestureDetector(child: new Text('区/县'))),
                    flex: 2,
                  )
                ],
              ),
            )));
    var tel = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '电话号码',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '*',
                              style: TextStyle(fontSize: 14, color: Colors.red))
                        ]),
                  ),
                ),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        controller: _mobiletroller,
                        keyboardType: TextInputType.number,
                        decoration: InputDecoration(
                          hintText: '请输入电话号码',
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 2,
              )
            ],
          ),
        ));
    var valid = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new Text(
                      '验证码',
                      style: TextStyle(
                          fontSize: 15,
                          color: Color.fromRGBO(102, 102, 102, 1)),
                    )),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        controller: _validtroller,
                        decoration: InputDecoration(
                          hintText: '验证码',
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: Align(
                      alignment: Alignment.centerRight,
                      child: new Container(
                        child: new Material(
                          //INK可以实现装饰容器
                          child: new Ink(
                            //用ink圆角矩形
                            // color: Colors.red,
                            decoration: new BoxDecoration(
                              //背景
                              color: Colors.white,
                              //设置四周圆角 角度
                              borderRadius:
                                  BorderRadius.all(Radius.circular(5.0)),
                              //设��四周边框
                              border: new Border.all(
                                  width: 1,
                                  color: Color.fromRGBO(27, 182, 251, 1)),
                            ),
                            child: new InkWell(
                                //圆角设置,给水波纹也设置同样的圆角
                                //如果这里不设置就会出现矩形的水波纹效果
                                borderRadius: new BorderRadius.circular(15.0),
                                //设置点击事件回调
                                onTap: () {
                                  if (_seconds == 60) {
                                    sendcode();
                                  }
                                },
                                child: Container(
                                  //设置 child 居中
                                  alignment: Alignment(0, 0),
                                  height: 35,
                                  width: 105,
                                  child: Text(
                                    _verifyStr,
                                    style: TextStyle(
                                        color: Color.fromRGBO(27, 182, 251, 1)),
                                  ),
                                )),
                          ),
                        ),
                      )
                      // child: new RaisedButton(
                      //   child: Text('申请补考'),
                      //   onPressed: () {},
                      // ),
                      ),
                  // child: new RaisedButton(
                  //   onPressed: () {
                  //     sendcode();
                  //   },
                  //   child: Text('获取验证码'),
                  // ),
                ),
                flex: 1,
              )
            ],
          ),
        ));
    var code = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new Text(
                      '身份证号',
                      style: TextStyle(
                          fontSize: 15,
                          color: Color.fromRGBO(102, 102, 102, 1)),
                    )),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        controller: _idcardtroller,
                        decoration: InputDecoration(
                          hintText: '请输入身份证号',
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 2,
              )
            ],
          ),
        ));
    var cardimg = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '照片',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '（身份证正、反两面）',
                              style: TextStyle(
                                  fontSize: 12,
                                  color: Color.fromRGBO(102, 102, 102, 1)))
                        ]),
                  ),
                ),
              ),
              // Expanded(
              //   child: new Padding(
              //       padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
              //       child: new TextField(

              //           decoration: InputDecoration(
              //             hintText: '请输入身份证号',
              //         border: OutlineInputBorder(
              //          borderSide: BorderSide.none,
              //         ),
              //       ))),
              //   flex: 2,
              // )
            ],
          ),
        ));

    var cardimg1 = Padding(
        padding: new EdgeInsets.fromLTRB(0, 0, 0, 0),
        child: Container(
          color: Colors.white,
          height: 100,
          child: new Row(
            children: <Widget>[
              Expanded(
                  child: new Padding(
                    padding: new EdgeInsets.fromLTRB(0, 0, 10, 10),
                    child: new GestureDetector(
                        onTap: () {
                          getImage(1, 1);
                        },
                        child:
                        card_z==""?Image.asset("resource/images/user/card_img1.png"):
                        CachedNetworkImage(imageUrl: card_z,)
                        // child: FadeInImage.assetNetwork(
                        //   placeholder: "resource/images/user/card_img1.png",
                        //   image: card_z,
                        // )
                        ),
                    // new Image.asset('resource/images/user/card_img1.png'),
                  ),
                  flex: 1),
              Expanded(
                  child: new Padding(
                    padding: new EdgeInsets.fromLTRB(0, 0, 10, 10),
                    child: new GestureDetector(
                        onTap: () {
                          getImage(2, 2);
                        },
                        child:
                        card_f==""?Image.asset("resource/images/user/card_img2.png"):
                        CachedNetworkImage(imageUrl: card_f,)
                        // child: FadeInImage.assetNetwork(
                        //   placeholder: "resource/images/user/card_img2.png",
                        //   image: card_f,
                        // )
                        ),
                    // new Image.asset('resource/images/user/card_img2.png'),
                  ),
                  flex: 1),
            ],
          ),
        ));
    var experice = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '相关工作经历',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '',
                              style: TextStyle(
                                  fontSize: 12,
                                  color: Color.fromRGBO(102, 102, 102, 1)))
                        ]),
                  ),
                ),
              ),
            ],
          ),
        ));
    var expericetext = Padding(
        padding: new EdgeInsets.fromLTRB(0, 0, 0, 0),
        child: Container(
          color: Colors.white,
          height: 150,
          child: new Column(
            children: <Widget>[
              new Padding(
                padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                child: TextField(
                  maxLines: 5,
                  controller: _expricetroller,
                  decoration: InputDecoration(
                      border: InputBorder.none,
                      fillColor: Color.fromRGBO(238, 238, 238, 1),
                      filled: true,
                      labelText: '输入工作经历'),
                ),
              ),
            ],
          ),
        ));
    var pass = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '登录密码',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '*',
                              style: TextStyle(fontSize: 14, color: Colors.red))
                        ]),
                  ),
                ),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        controller: _passtroller,
                        decoration: InputDecoration(
                          hintText: '请输入登录密码',
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 2,
              )
            ],
          ),
        ));
    var confirmpass = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '再次确认',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '*',
                              style: TextStyle(fontSize: 14, color: Colors.red))
                        ]),
                  ),
                ),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        controller: _confirmpasstroller,
                        decoration: InputDecoration(
                          hintText: '请输入密码',
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 2,
              )
            ],
          ),
        ));
    var agreen = Padding(
        padding: new EdgeInsets.fromLTRB(10, 10, 0, 0),
        child: Row(
          // crossAxisAlignment: CrossAxisAlignment.baseline,
          children: <Widget>[
            // Expanded(
            //   flex: 1,
            //   child:
            Container(
              alignment: new FractionalOffset(0.0, 0.0),
              width: 20,
              height: 20,
              child: Checkbox(
                activeColor: Color.fromRGBO(27, 182, 251, 1),
                checkColor: Colors.blue,
                value: this.agreen,
                onChanged: (value) {
                  setState(() {
                    this.agreen = value;
                  });
                },
              ),
            ),
            // Expanded(
            //   flex:2,
            //   child:
            Padding(
                padding: new EdgeInsets.fromLTRB(5, 0, 0, 0),
                child: Container(
                    child: GestureDetector(
                  onTap: () {
                    Navigator.of(context)
                        .push(new MaterialPageRoute(builder: (_) {
                      return new AgreementPage();
                    }));
                  },
                  child: RichText(
                    text: TextSpan(
                        text: '我已经阅读并同意',
                        style: TextStyle(
                            fontSize: 12, color: Color.fromRGBO(51, 51, 51, 1)),
                        children: [
                          TextSpan(
                              text: '【车魔估检测师入职协议】',
                              style: TextStyle(
                                fontSize: 12,
                                color: Color.fromRGBO(27, 182, 251, 1),
                              ))
                        ]),
                  ),
                )))
            //)
          ],
        ));
    var btn = Padding(
      padding: new EdgeInsets.fromLTRB(10, 20, 10, 10),
      child: new SizedBox(
          width: double.infinity,
          height: 45,
          child: new RaisedButton(
            child: Text('提交'),
            textColor: Colors.white,
            color: Color.fromRGBO(27, 182, 251, 1),
            onPressed: () {
              review(0);
            },
          )),
    );


    var save = Padding(
      padding: new EdgeInsets.fromLTRB(10, 20, 10, 10),
      child: new SizedBox(
          width: double.infinity,
          height: 45,
          child: new RaisedButton(
            child: Text('保存信息'),
            textColor: Colors.white,
            color: Color.fromRGBO(27, 182, 251, 1),
            onPressed: () {
             saveinfo();
            },
          )),
    );

    var onlineScore = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new Text(
                      '线上测试分数',
                      style: TextStyle(
                          fontSize: 15,
                          color: Color.fromRGBO(102, 102, 102, 1)),
                    )),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child:new Text(score)
                    // child: new TextField(
                    //     controller: _idcardtroller,
                    //     decoration: InputDecoration(
                    //       hintText: '请输入身份证号',
                    //       border: OutlineInputBorder(
                    //         borderSide: BorderSide.none,
                    //       ),
                    //     ))
                        ),
                flex: 2,
              )
            ],
          ),
        ));

         var underlineScore = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new Text(
                      '线下测试分数',
                      style: TextStyle(
                          fontSize: 15,
                          color: Color.fromRGBO(102, 102, 102, 1)),
                    )),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child:new Text(underlinescore)
                    // child: new TextField(
                    //     controller: _idcardtroller,
                    //     decoration: InputDecoration(
                    //       hintText: '请输入身份证号',
                    //       border: OutlineInputBorder(
                    //         borderSide: BorderSide.none,
                    //       ),
                    //     ))
                        ),
                flex: 2,
              )
            ],
          ),
        ));

         var onlinename = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new Text(
                      '线下测试人',
                      style: TextStyle(
                          fontSize: 15,
                          color: Color.fromRGBO(102, 102, 102, 1)),
                    )),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child:new Text(underlinename)
                    // child: new TextField(
                    //     controller: _idcardtroller,
                    //     decoration: InputDecoration(
                    //       hintText: '请输入身份证号',
                    //       border: OutlineInputBorder(
                    //         borderSide: BorderSide.none,
                    //       ),
                    //     ))
                        ),
                flex: 2,
              )
            ],
          ),
        ));


    tiles.add(name);
    tiles.add(age);
    tiles.add(city);
    tiles.add(site);
    tiles.add(tel);
    // tiles.add(valid);
    tiles.add(code);
    tiles.add(cardimg);
    tiles.add(cardimg1);
    tiles.add(experice);
    tiles.add(expericetext);
    if(status_string!='待审核'&&status_string!='审核驳回'){
      tiles.add(onlineScore);
      tiles.add(underlineScore);
      tiles.add(onlinename);
    }
    if (status_string == "待审核" ||
        status_string == "审核驳回" ||
        status_string == "等待最终审核" ||
        status_string == "最终审核不通过") {
      tiles.add(shenhe());
      tiles.add(shenheText());
    }
    if (status_string == "等待线下测试") {
      tiles.add(underTest());
    }

    // tiles.add(pass);
    // tiles.add(confirmpass);
    // tiles.add(agreen);
    if (status_string != '等待线上测试'&&status_string != '正式检测师') {
      tiles.add(btn);
    }
    tiles.add(save);
    // for (var item in formList) {
    //   tiles.add(Padding(
    //       padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
    //       child: Container(
    //           color: Colors.white,
    //           height: 50,
    //           child: new Row(
    //             children: <Widget>[
    //               Expanded(
    //                 child: new Padding(
    //                     padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
    //                     child: new Text(
    //                       item['title'],
    //                       style: TextStyle(fontSize: 15,color: Color.fromRGBO(102, 102, 102, 1)),
    //                     )),
    //                 flex: 1,
    //               ),
    //               new Padding(
    //                   padding: new EdgeInsets.fromLTRB(0, 0, 10, 0),
    //                   child: new Text(
    //                     item['sub_title'],
    //                     style:
    //                         TextStyle(fontSize: 15, color: item['sub_color']),
    //                   )),
    //             ],
    //           ))));
    // }

    content = new Column(
        children: tiles //重点在这里，因为用编辑器写Column生成的children后面会跟一个<Widget>[]，
        //此时如果我们直接把生成的tiles放在<Widget>[]中是会报一个类型不匹配的错误，把<Widget>[]删了就可以了
        );
    return content;
  }
  saveinfo(){
    Map<String, String> map = new Map();
    map['id'] = this.sid;
    map["mobile"] = _mobiletroller.text.trim();
   
    map["name"] = _nametroller.text.trim();
    map["workhistory"] = _expricetroller.text.trim();
    map["lengthofservice"] = _agetroller.text.trim();
    map["idcard"] = _idcardtroller.text.trim();
   
    map["idcardback"] = card_f;
    map["idcardfront"] = card_z;

    map['provinceId'] = provinceId;
    map['provinceName'] = provinceName;
    map['cityName'] = cityName;

    map['cityId'] = cityId;
    map['areaName'] = areaName;
    map['areaId'] = areaId;
    map['site_id']=siteId;
    map['status']="4";

    HttpHelper.post(HttpHelper.API_Inspectorreview, (data) {
      if (data != null) {
        print(data);
        Toast.show(data["msg"], context);

        if (data["code"].toString() == "1") {
          Navigator.pop(context);
        }
      }
    }, params: map);
  }

  review(save) {
    Map<String, String> map = new Map();
    map['id'] = this.sid;
    if (status_string == '待审核' || status_string == '审核驳回') {
      map['status'] = "1";
      map["mobile"] = _mobiletroller.text.trim();
   
    map["name"] = _nametroller.text.trim();
    map["workhistory"] = _expricetroller.text.trim();
    map["lengthofservice"] = _agetroller.text.trim();
    map["idcard"] = _idcardtroller.text.trim();
   
    map["idcardback"] = card_f;
    map["idcardfront"] = card_z;

    map['provinceId'] = provinceId;
    map['provinceName'] = provinceName;
    map['cityName'] = cityName;

    map['cityId'] = cityId;
    map['areaName'] = areaName;
    map['areaId'] = areaId;
    map['site_id']=siteId;
    // if(save==1){
    //   map['status']='4';
    // }else{

      if (infostaus == "通过") {
        map['status_code'] = '1';
      } else {
        if (_failresonController.text == "") {
          Toast.show('请输入不通过原因', context);
          return;
        }
        map['status_code'] = '2';
        map['failreason'] = _failresonController.text;
      }
    } else if (status_string == "等待线下测试") {
      if (_undertestnameController.text == "" ||
          _undertestscroeController.text == "") {
        Toast.show('请输入线下测试信息', context);
        return;
      }
      map['status'] = "2";
      map['underline_test_name'] = _undertestnameController.text;
      map['underline_score'] = _undertestscroeController.text;
    } else if (status_string == "等待最终审核" || status_string == "最终审核不通过") {
      map['status'] = "3";
      if (infostaus == "通过") {
        map['status_code'] = '1';
      } else {
        if (_failresonController.text == "") {
          Toast.show('请输入不通过原因', context);
          return;
        }
        map['status_code'] = '2';
        map['failreason'] = _failresonController.text;
      }
    }
    // }

    //map["registed_Id"]=pref.getString('registeid');

    HttpHelper.post(HttpHelper.API_Inspectorreview, (data) {
      if (data != null) {
        print(data);
        Toast.show(data["msg"], context);

        if (data["code"].toString() == "1") {
          Navigator.pop(context);
        }
      }
    }, params: map);
  }

  Widget shenhe() {
    Widget titles = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              // Expanded(
              //   child:
              new Padding(
                padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                child: Text('资料审核',
                    style: TextStyle(
                        fontSize: 15, color: Color.fromRGBO(102, 102, 102, 1))),
              ),
              // ),
              // Expanded(child:
              Radio<String>(
                  materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
                  //当前Radio的值
                  hoverColor: Color.fromRGBO(200, 200, 200, 1),
                  focusColor: Color.fromRGBO(25, 172, 249, 1),
                  value: '通过',
                  activeColor: Color.fromRGBO(25, 172, 249, 1),
                  groupValue: infostaus,
                  // groupValue: defaultv,
                  onChanged: (value) {
                    setState(() {
                      infostaus = value;
                    });
                  }),

              // )
              Text('通过'),
              Padding(
                padding: new EdgeInsets.fromLTRB(15, 0, 5, 0),
                child: Radio<String>(
                    materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
                    //当前Radio的值
                    hoverColor: Color.fromRGBO(200, 200, 200, 1),
                    focusColor: Color.fromRGBO(25, 172, 249, 1),
                    value: '不通过',
                    activeColor: Color.fromRGBO(25, 172, 249, 1),
                    groupValue: infostaus,
                    // groupValue: defaultv,
                    onChanged: (value) {
                      setState(() {
                        infostaus = value;
                      });
                    }),
              ),
              Text('不通过'),
            ],
          ),
        ));
    return titles;
  }

  Widget shenheText() {
    Widget titles = infostaus == '不通过'
        ? Padding(
            padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
            child: Container(
                color: Colors.white,
                height: 50,
                child: new TextField(
                    controller: _failresonController,
                    decoration: InputDecoration(
                      hintText: '不通过理由',
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                    ))))
        : new Container(height: 0);
    return titles;
  }

  //线下测试
  Widget underTest() {
    Widget content = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
            color: Colors.white,
            // height: 150,
            width: double.infinity,
            child: new Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                Padding(
                    padding: new EdgeInsets.fromLTRB(12, 10, 0, 0),
                    child: Text('线下测试信息')),
                Padding(
                    padding: new EdgeInsets.fromLTRB(10, 10, 0, 0),
                    child: new TextField(
                        controller: _undertestnameController,
                        decoration: InputDecoration(
                          hintText: '测试人',
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 0, 0),
                    child: new TextField(
                        controller: _undertestscroeController,
                        decoration: InputDecoration(
                          hintText: '分数',
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
              ],
            )
            // new TextField(
            //     controller: _failresonController,
            //     decoration: InputDecoration(
            //       hintText: '不通过理由',
            //       border: OutlineInputBorder(
            //         borderSide: BorderSide.none,
            //       ),
            //     ))
            ));
    return content;
  }

//注册
  void regist() async {
    SharedPreferences pref = await SharedPreferences.getInstance();
    FocusScope.of(context).requestFocus(FocusNode());

    var toastmsg = "";
    if (_nametroller.text.trim().length == 0) {
      toastmsg = '请填写姓名';
    } else if (_agetroller.text.trim().length == 0) {
      toastmsg = '请填写工龄';
    } else if (_mobiletroller.text.trim().length == 0) {
      toastmsg = '请填写电话号码';
    } else if (_validtroller.text.trim().length == 0) {
      toastmsg = '请填写验证码';
    } else if (_idcardtroller.text.trim().length == 0) {
      toastmsg = '请填写身份证';
    } else if (_expricetroller.text.trim().length == 0) {
      toastmsg = '请填写工作经验';
    } else if (_passtroller.text.trim().length == 0) {
      toastmsg = '请填写登录密码';
    } else if (_confirmpasstroller.text.trim().length == 0) {
      toastmsg = '请填写密码';
    } else if (agreen == false) {
      toastmsg = '请勾选入职协议';
    }

    if (toastmsg != "") {
      Toast.show(toastmsg, context);
      return;
    }

    Map<String, String> map = new Map();
    map["mobile"] = _mobiletroller.text.trim();
    map["code"] = _validtroller.text.trim();
    map["name"] = _nametroller.text.trim();
    map["workhistory"] = _expricetroller.text.trim();
    map["lengthofservice"] = _agetroller.text.trim();
    map["idcard"] = _idcardtroller.text.trim();
    map["password"] = _passtroller.text.trim();
    map["idcardback"] = card_f;
    map["idcardfront"] = card_z;

    map['provinceId'] = provinceId;
    map['provinceName'] = provinceName;
    map['cityName'] = cityName;

    map['cityId'] = cityId;
    map['areaName'] = areaName;
    map['areaId'] = areaId;

    if (pref.getString('role') == "1") {
      map["partner_id"] = pref.getString('uid');
    } else {
      map["site_id"] = pref.getString('uid');
    }
    //map["registed_Id"]=pref.getString('registeid');

    HttpHelper.post(HttpHelper.API_Reg, (data) {
      if (data != null) {
        print(data);
        Toast.show(data["msg"], context);

        if (data["code"].toString() == "1") {
          Navigator.pop(context);
        }
      }
    }, params: map);
  }

//发送验证码
  sendcode() {
    FocusScope.of(context).requestFocus(FocusNode());

    if (_mobiletroller.text.trim().length == 0) {
      Toast.show("填写手机号", context);
      return;
    }
    Map<String, String> map = new Map();
    map["mobile"] = _mobiletroller.text.trim();
    HttpHelper.post(HttpHelper.API_SendCode, (data) {
      if (data != null) {
        print(data);
        Toast.show(data["msg"], context);

        if (data["code"].toString() == "1") {
          // Navigator.pop(context);
          //_startTimer();
          setState(() {
            // orderInfo=data["data"];
          });
        }
      }
    }, params: map);
  }

  //选择图片
  getimgs(type, card) async {
    if (type == 1) {
      var image = await ImagePicker.pickImage(source: ImageSource.gallery);

      setState(() {
        _image = image;
        select_img = true;
      });
    } else {
      var image = await ImagePicker.pickImage(source: ImageSource.camera);

      setState(() {
        _image = image;
        select_img = true;
      });
    }
    if (_image == null) return;
    Map<String, String> map = new Map();

    HttpHelper.upLoadImage(_image, (data) {
      if (card == 1) {
        setState(() {
          card_z = data["url"];
        });
      } else {
        setState(() {
          card_f = data["url"];
        });
      }
    }, params: map);
  }

//选择图片方���
  Future getImage(type, idx) async {
    FocusScope.of(context).requestFocus(FocusNode());
    showDialog(
        context: context,
        builder: (BuildContext context) {
          // return new Container(
          //     height: 300,
          //     child: GestureDetector(
          //         onTap: () {
          //           Navigator.pop(context);
          //         },
          //         child: FadeInImage.assetNetwork(
          //             placeholder: "resource/images/user/card_img1.png",
          //             image: idx == 1 ? card_z : card_f)));
          return new SimpleDialog(
            title: new Text('选择'),
            children: <Widget>[
              new SimpleDialogOption(
                child: new Text('查看图片'),
                onPressed: () {
                  Navigator.pop(context);
                  showLargeImg(type);
                },
              ),
              new SimpleDialogOption(
                child: new Text('相机'),
                onPressed: () {
                  Navigator.pop(context);
                  getimgs(0, type);
                },
              ),
              new SimpleDialogOption(
                child: new Text('相册'),
                onPressed: () {
                  Navigator.pop(context);
                  getimgs(1, type);
                },
              ),
              
            ],
          );
        });
    // var image = await ImagePicker.pickImage(source: ImageSource.gallery);
    // //_upLoadImage(image);//上传图片
    // setState(() {
    //   _image = image;
    // });
  }
 showLargeImg(idx){
FocusScope.of(context).requestFocus(FocusNode());
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return new Container(
              height: 300,
              child: GestureDetector(
                  onTap: () {
                    Navigator.pop(context);
                  },
                  child:CachedNetworkImage(imageUrl: idx == 1 ? card_z : card_f)
                  //  FadeInImage.assetNetwork(
                  //     placeholder: "resource/images/user/card_img1.png",
                  //     image: idx == 1 ? card_z : card_f)
                      ));
        });
 }
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(
          '审核检测师信息',
          style: TextStyle(color: Colors.black),
        ),
        backgroundColor: Colors.white,
        elevation: 0,
        iconTheme: IconThemeData(
          color: Colors.black, //修改颜色
        ),
        // backgroundColor: Color.fromRGBO(255, 204, 48, 1),
      ),
      body: new Center(
          child: Container(
        decoration: new BoxDecoration(
          color: Color.fromRGBO(238, 238, 238, 1),
        ),
        child: Padding(
            padding: new EdgeInsets.fromLTRB(0, 15, 0, 0),
            child: new ListView(
              children: <Widget>[buildcontent()],
            )),
      )),
    );
  }
}
